<template>
  <div class="main-settings">
    <div class="setting-items" v-for="(item, index) in settings" :key="index">
      <span>{{item.name}}</span>
      <img :src="getIcon(item.status)" class="item-switch" @click="item.status = !item.status"/>
    </div>
    <div class="setting-items">
      <span>删除当前模块</span>
      <div @click="delMod" class="item-delete item-switch">删除</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'RSetting',
  data () {
    return {
      settings: []
    }
  },
  props: ['value'],
  created () {
    this.settings = this.value
  },
  methods: {
    getIcon (status) {
      return require(`@/assets/resume/${status ? 'switch_off' : 'switch_on'}.svg`)
    },
    delMod () {
      this.$store.commit('DEL_MOD', {id: this.$parent.compId})
    }
  },
  watch: {
    value: function (newVal) {
      this.settings = newVal
    },
    settings: {
      handler (newVal) {
        this.$emit('input', newVal)
      },
      deep: true
    }
  }
}
</script>

<style scoped lang="less">
  .main-settings {
    font-size: 12px;
    position: absolute;
    right: -10px;
    top: 30px;
    padding: 15px 10px 0 10px;
    border: whitesmoke 1px solid;
    box-shadow: 10px 10px 10px whitesmoke;
    z-index: 3;
    background: white;

    .setting-items {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      width: 150px;
      margin-bottom: 15px;

      .item-switch {
        height: 20px;
        cursor: pointer;
      }
    }

    .item-delete {
      box-sizing: border-box;
      width: 36.99px;
      color: lightskyblue;
      border: 1px lightskyblue solid;
      border-radius: 10px;
      display: flex;
      justify-content: center;
      align-content: center;
    }

    &:before {
      content: "";
      display: block;
      position: absolute;
      right: 10px;
      top: -10px;
      width: 0;
      height: 0;
      border-bottom: 10px whitesmoke solid;
      border-left: 10px transparent solid;
      border-right: 10px transparent solid;
    }

    &:after {
      content: "";
      display: block;
      position: absolute;
      right: 10px;
      top: -9px;
      width: 0;
      height: 0;
      border-bottom: 10px white solid;
      border-left: 10px transparent solid;
      border-right: 10px transparent solid;
    }
  }
</style>
